from django.db import models

# Create your models here.

# 会员模型
class Users(models.Model):
    # 用户名 密码 手机号 邮箱 性别 年龄 头像 注册时间 状态
    username = models.CharField(max_length = 50)
    # 密码存的是加密后的 所以长度至少为77位
    password = models.CharField(max_length = 77)
    # 国际需要 + 3位长度 +86
    phone = models.CharField(max_length = 11)
    email = models.CharField(max_length = 100,null = True)
    sex = models.CharField(max_length = 1,choices=((1,'男'),(0,'女')),null = True)
    age = models.IntegerField(default=20)
    pic_url = models.CharField(max_length = 100,null = True)
    # 0表示正常 1 表示禁用 3 表示删除
    status = models.IntegerField(default = 0)
    addtime = models.DateTimeField(auto_now_add = True)


# 商品分类模型
class Cates(models.Model):
    name = models.CharField(max_length = 50)
    pid = models.IntegerField()
    path = models.CharField(max_length = 100)
    

# 商品模型
class Goods(models.Model):
    title = models.CharField(max_length = 255)
    cateid = models.ForeignKey(to = 'Cates')
    price = models.FloatField()
    store = models.IntegerField()
    info = models.TextField()
    pic_url = models.CharField(max_length = 100)
    # 0 新品 1 热卖 2 下架 -1表示删除
    status = models.IntegerField(default = 0)
    clicknum = models.IntegerField(default = 0)
    ordernum = models.IntegerField(default = 0)
    addtime = models.DateTimeField(auto_now_add = True)


# 购物车
class Cart(models.Model):
    # id uid gid num
    uid = models.ForeignKey(to = 'Users')
    goodsid = models.ForeignKey(to = 'Goods')
    num = models.IntegerField()



# 收货地址模型
class Address(models.Model):
    uid = models.ForeignKey(to = "Users")
    shr = models.CharField(max_length = 50)
    shdh = models.CharField(max_length = 11)
    sheng = models.IntegerField()
    shi = models.IntegerField()
    xian = models.IntegerField()
    info = models.CharField(max_length = 100)
    isChecked = models.BooleanField(default = False)


# 城市数据
class Citys(models.Model):
    name = models.CharField(max_length=255)
    level = models.IntegerField()
    upid = models.IntegerField()

    class Meta:
        db_table = 'citys'




# 订单模型
class Order(models.Model):
    uid = models.ForeignKey(to = "Users")
    shr = models.CharField(max_length = 50)
    shdh = models.CharField(max_length = 11)
    shdz = models.CharField(max_length = 100)
    buytype = models.CharField(max_length = 10)
    wl = models.CharField(max_length = 10)
    totalprice = models.FloatField()
    addtime = models.DateTimeField(auto_now_add = True)
    buytime = models.DateTimeField(null = True)
    # 0  新订单   1    已支付,待发货 2   已发货 3   已收货 4   未评价 5   已删除
    status = models.IntegerField(default = 0)



# 订单详情模型
class OrderInfo(models.Model):
    orderid = models.ForeignKey(to = "order")
    goodsid = models.IntegerField()
    title = models.CharField(max_length = 255)
    price = models.FloatField()
    pic_url = models.CharField(max_length = 100)
    num = models.IntegerField()